<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
	public function __construct() {
		parent::__construct();
	}

	/**
	 * 登录页面
	 */
    public function index(){
		/* 拦截已登录 */
		if(!empty($_SESSION['admin'])) {
			header('Location:'.U('Index/index'));
		}
		if(IS_POST) {
			$Admin = D('admin');
			/*判断是否登录成功*/
			$info = $Admin->checkadmin();
			if(!empty($info)) { // 成功
				$_SESSION['admin'] = $info;
				$this->success('登录成功！',U('Address/index'));
			} else { // 失败
				$this->error('登录失败');
			}
			die();
		} 
		$this->display();
    }

	/**
	 * 退出
	 */	
	public function out() {
		/* 拦截已登录 */
		if(!empty($_SESSION['admin'])) {
			header('Location:'.U('Index/index'));
		}
		unset($_SESSION['admin']);
		header('Location:'.U('Login/index'));
	}

	public function test() {
		$manarr = M('code')->select();
		$man = array();
		foreach($manarr as $key=>$value) {
			$man[$value['ecode']] = $value;
		}
		$data = D('order')->mselect2(); 
		$list = array();
		foreach($data as $k=>$v) {
			$list[$v['code']][] = $v;
		}

		echo '<table border="1">';
		foreach($list as $lk => $lv) {
			echo "<tr>";
			echo "<td colspan='5'>
				姓名：{$man[$lk]['ename']}
				推广码：{$man[$lk]['ecode']}
				人数：".count($lv)."人</td>";
			echo "</tr>";
			echo "<tr>";
				echo "<td>姓名</td>";
				echo "<td>电话</td>";
				echo "<td>公司名称</td>";
				echo "<td>地址</td>";
				echo "<td>订单号</td>";
			echo "</tr>";
			foreach($lv as $vk => $vv) {
				echo "<tr>";
					echo "<td>　　{$vv['nickname']}</td>";
					echo "<td>{$vv['mobile']}</td>";
					echo "<td>{$vv['company']}</td>";
					echo "<td>{$vv['address']}</td>";
					echo "<td>{$vv['transaction_id']}</td>";
				echo "</tr>";
			}
		}
		echo '</table>';
	}

}
